package main

import (
	"encoding/json"
	"fmt"
	"reflect"
)

type personT struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func main() {
	p := personT{Name: "zhangsan", Age: 18}
	jsonP, err := json.Marshal(p)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(string(jsonP))
	}
	fmt.Println(p)
	respJSON := "{\"name\":\"lisi\",\"age\":33}"
	json.Unmarshal([]byte(respJSON), &p)
	fmt.Println(p)
	pt := reflect.TypeOf(p)
	for i := 0; i < pt.NumField(); i++ {
		sf := pt.Field(i)
		fmt.Printf("%s  %s\n", sf.Name, sf.Tag.Get("json"))
	}
}
